package com.framework.base.taglib.ui; 

import java.util.HashMap;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.framework.base.constant.WebConstants;

/**
 * @Description:用于管理权限
 * @Company: www.51wuxia.com
 * @version 1.0
 */
public class ModuleTag extends TagSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -566837912880701125L;
	private String moduleID;//模块ID
	  public ModuleTag() {
	    moduleID="";
	  }
	  @SuppressWarnings({ "unchecked", "static-access" })
	  public int doStartTag()  throws JspException{
		  //rightMap保存为key=moduleID,value=operation1,operation2
	      HashMap<String,String> rightMap = (HashMap<String,String>)pageContext.getSession().getAttribute(WebConstants.USERPERMISSIONS);
	      boolean hasPermission = false;
	      if (rightMap!=null&&rightMap.get(moduleID) != null && !"".equals(rightMap.get(moduleID)))
	          hasPermission = true;
	      if (hasPermission)
	          return this.EVAL_BODY_INCLUDE;
	      return this.SKIP_BODY;
	  }

	    /**
	     *
	     * @return
	     * @throws JspException
	     */
	  public int doEndTag() throws JspException{
	      return super.doEndTag();
	  }
	  public String getModuleID() {
	    return moduleID;
	  }
	  public void setModuleID(String moduleID) {
	    this.moduleID = moduleID;
	  }
}
